/*
 * Copyright (C) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef NFC_WATCH_DOG_H
#define NFC_WATCH_DOG_H
#include <condition_variable>
#include <mutex>
#include <string>
#include <thread>
#include "inci_nfcc_interface.h"

namespace OHOS {
namespace NFC {
class NfcWatchDog final {
public:
    NfcWatchDog(const std::string& threadName, int timeout, std::weak_ptr<NCI::INciNfccInterface> nfccProxy);
    ~NfcWatchDog();
    void Cancel();
    void Run();

private:
    void MainLoop();

private:
    std::mutex mutex_ {};
    std::condition_variable conditionVariable_ {};
    std::string threadName_ {""};
    int timeout_ {0};
    volatile bool canceled_ {false};
    std::unique_ptr<std::thread> thread_ {};

    std::weak_ptr<NCI::INciNfccInterface> nciNfccProxy_;
};
}  // namespace NFC
}  // namespace OHOS
#endif  // NFC_WATCH_DOG_H
